package com.ymttest.database.sqlwapper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ymatou.iapi.refund.parameter.GetBuyerReturnBillsResp;
import com.ymt.database.SqlManager;
import com.ymttest.database.model.CS_ReturnApplyBill;
import com.ymttest.utils.EnvSetup;

public class CS_ReturnApplyBillWapper {
	SqlManager manager;

    public CS_ReturnApplyBillWapper() {
        manager = new SqlManager("ymtCS" + EnvSetup.getEnv());
    }

    public CS_ReturnApplyBill selectByPrimaryKey(String ReturnApplyBillId) {
    	CS_ReturnApplyBill model=new CS_ReturnApplyBill();
        List<CS_ReturnApplyBill> result = manager
                .getSelectResults(
                        "com.ymttest.database.mapping.CS_ReturnApplyBillMapper.selectByPrimaryKey",
                        ReturnApplyBillId);
        if(result.size()>0)
        	model=result.get(0);
        manager.commit();
        return model;
    }
    public List<CS_ReturnApplyBill> selectByApplyBillId(String ReturnApplyBillId) {
    	CS_ReturnApplyBill model=new CS_ReturnApplyBill();
        List<CS_ReturnApplyBill> result = manager
                .getSelectResults(
                        "com.ymttest.database.mapping.CS_ReturnApplyBillMapper.selectByApplyBillId",
                        ReturnApplyBillId);
        manager.commit();
        return result;
    }
    
    public Integer pagingBuyerRefundListCount(Integer buyerId,int platformSource) {
    	Map<String,Object> map=new HashMap();
    	map.put("buyerId", buyerId);
    	map.put("platformSource", platformSource);
    	CS_ReturnApplyBill model=new CS_ReturnApplyBill();
    	ArrayList result = (ArrayList) manager
                .getSelectResults(
                        "com.ymttest.database.mapping.CS_ReturnApplyBillMapper.pagingBuyerRefundListCount",
                        map);
        manager.commit();
        return Integer.parseInt(result.get(0).toString());
    }
    
    
    public List<CS_ReturnApplyBill> selectByBuyerIdAndFromSource(Integer buyerId,int platformSource) {
    	Map<String,Object> map=new HashMap();
    	map.put("buyerId", buyerId);
    	map.put("platformSource", platformSource);
    	List<CS_ReturnApplyBill> result = manager
                .getSelectResults(
                        "com.ymttest.database.mapping.CS_ReturnApplyBillMapper.selectByBuyerIdAndFromSource",
                        map);
        manager.commit();
        return result;
    }
    
    public List<CS_ReturnApplyBill> pagingBuyerRefundList(Integer buyerId,int pageIndex,int pageSize,int platformSource) {
    	Map<String,Object> map=new HashMap();
    	map.put("buyerId", buyerId);
    	map.put("pageIndex", pageIndex);
    	map.put("pageSize", pageSize);
    	map.put("platformSource",platformSource);
    	
    	List<CS_ReturnApplyBill> result = manager
                .getSelectResults(
                        "com.ymttest.database.mapping.CS_ReturnApplyBillMapper.pagingBuyerRefundList",
                        map);
        manager.commit();
        return result;
    }
    

    
    public int updateActionByReturnId(String returnId,int action) {
    	Map<String,Object> map=new HashMap();
    	map.put("returnId", returnId);
    	map.put("action", action);
    	int result = manager
                .update(
                        "com.ymttest.database.mapping.CS_ReturnApplyBillMapper.updateActionByReturnId",
                        map);
        manager.commit();
        return result;
    }
    
    public int updateTypeByReturnId(String returnId,int type) {
    	Map<String,Object> map=new HashMap();
    	map.put("returnId", returnId);
    	map.put("type", type);
    	int result = manager
                .update(
                        "com.ymttest.database.mapping.CS_ReturnApplyBillMapper.updateTypeByReturnId",
                        map);
        manager.commit();
        return result;
    }
    
    
    public int updateBuyerIdByReturnId(String returnId,int buyerId,int action) {
    	Map<String,Object> map=new HashMap();
    	map.put("returnId", returnId);
    	map.put("buyerId", buyerId);
    	map.put("action", action);
    	int result = manager
                .update(
                        "com.ymttest.database.mapping.CS_ReturnApplyBillMapper.updateBuyerIdByReturnId",
                        map);
        manager.commit();
        return result;
    }
    public int updateByPrimaryKey(CS_ReturnApplyBill model) {
    	int result = manager
                .update(
                        "com.ymttest.database.mapping.CS_ReturnApplyBillMapper.updateByPrimaryKey",
                        model);
        manager.commit();
        return result;
    }
    
    public List<CS_ReturnApplyBill> selectByOrderId(long orderId) {

        List<CS_ReturnApplyBill> result = manager
                .getSelectResults(
                        "com.ymttest.database.mapping.CS_ReturnApplyBillMapper.selectByOrderId",
                        orderId);
        manager.commit();
        return result;
    }
    public static void main(String[] args) {
    	CS_ReturnApplyBillWapper test = new CS_ReturnApplyBillWapper();

        System.out.println(test.selectByPrimaryKey("TH180613000006136").getCatalogId());
        // test.insertYmtCouponSetting(3,11);
        // Logger.debug(test.getLastYmtCouponSettingId());


    }
}
